package com.pangus.toolkits.files.http;


import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import okhttp3.Headers;

import javax.annotation.Nullable;

/**
 * @author yingheng chen
 * @description 包装原生的ok-http的返回
 * @date 2019/12/3
 */
@Data
public class Response<T> {
    public static <T> Response<T> success(@Nullable T data, okhttp3.Response response, @Nullable JSONObject jsonObject) {
        return new Response<>(data, response, jsonObject);
    }

    private final okhttp3.Response rawResponse;
    private JSONObject jsonObject;
    @Nullable
    private final T data;

    private Response(@Nullable T data, okhttp3.Response rawResponse, JSONObject jsonObject) {
        this.data = data;
        this.rawResponse = rawResponse;
        this.jsonObject = jsonObject;
    }

    public Headers getHeaders() {
        return rawResponse.headers();
    }

    public String rawMessage() {
        return rawResponse.message();
    }
}
